﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibSnesDotNet.Input
{
	public abstract class InputProvider
	{
		public event EventHandler<InputReceivedEventArgs> InputReceived;

		public void ReportNextInput(Predicate<InputReceivedEventArgs> predicate, Action<Input> callback)
		{
			EventHandler<InputReceivedEventArgs> Handler = null;
			EventHandler<InputReceivedEventArgs> temp = (s, e) =>
			{
				if (predicate == null || predicate(e))
				{
					InputReceived -= Handler;

					callback(e.Input);
				}
			};
			Handler = temp;

			InputReceived += Handler;
		}

		protected void OnInputReceived(InputReceivedEventArgs e)
		{
			if (InputReceived != null) { InputReceived(this, e); }
		}
	}
}
